//   Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <string>
#include <vector>
#include <memory>
#include <utility>
#include <ctime>
#include <mutex>
#include <opencv2/opencv.hpp>

#include "common/model_config.h"
#include "rockchip/base/rk_predictor.h"
#include "rockchip/rkmodel_manager.h"


namespace ai {

class RKDetPredictor : public RKPredictor {
public:
  RKDetPredictor(RKPackPredictor* model, RKModelManager* mng, LogInfo *lg);
  ~RKDetPredictor(){}

private:
  int RunDet(stream::ImageBlob* blob, std::vector<BaseInfo*>& det_infos);


  int PostProcess(std::vector<BaseInfo*>& det_infos, 
                int cur_block,
                RKModelManager* mng, 
                int md_idx);
private:
  int start_postprocess_thread_imp();
  int GenerateMeshGrid();

  int GetConvDetectionResult(stream::ImageBlob& img_blob, std::vector<int> &qnt_zp, std::vector<float> &qnt_scale, std::vector<BaseInfo*>& det_infos);
  int GetConvDetectionResult_out1(stream::ImageBlob& img_blob, rknn_tensor_attr* output_attrs, std::vector<BaseInfo*>& det_infos);

  float sigmoid(float x);
  void ParseTensor(float* out_data, int layer, 
    std::vector<cv::Rect>& boxs, std::vector<float>& scores, std::vector<int>& labels,
    std::vector<int> ori_shape, std::vector<int> feteature_shape, ModelConfig* cfg);


private:
  std::vector<float> MeshGrid;
  int HeadNum;
  int TopK = 50;
  
};



}  // namespace hb
